package br.gov.ibama.client.visao;

import java.util.List;

import br.gov.ibama.client.componentes.BasisComponentes;

import com.smartgwt.client.data.DataSource;
import com.smartgwt.client.widgets.ImgButton;
import com.smartgwt.client.widgets.grid.ListGrid;
import com.smartgwt.client.widgets.grid.ListGridField;
import com.smartgwt.client.widgets.layout.HLayout;
import com.smartgwt.client.widgets.toolbar.ToolStrip;

public abstract class VisaoIndice extends HLayout {

	private ListGrid gradePrincipal;
	private ToolStrip barraDeBotoes;
	
	public VisaoIndice() {
		criaGradePrincipal();
		criaBarraDeBotoes();
		setWidth100();
		setHeight100();
		setMembers(gradePrincipal, barraDeBotoes);
		setClickHandlerGrid();
	}
	
	protected void criaBarraDeBotoes() {
		barraDeBotoes = BasisComponentes.criaBarraDeBotoesVertical();
		List<ImgButton> botoes = getBotoes();
		barraDeBotoes.setMembers(botoes.toArray(new ImgButton[botoes.size()]));
	}

	protected void criaGradePrincipal() {
		gradePrincipal = BasisComponentes.criaListGridIndice(getDataSource());
		gradePrincipal.setDataSource(getDataSource());
		List<ListGridField> camposDaGrade = getCamposDaGrade();
		gradePrincipal.setFields(camposDaGrade.toArray(new ListGridField[camposDaGrade.size()]));
	}

	public ListGrid getGradePrincipal() {
		return gradePrincipal;
	}

	public void setGradePrincipal(ListGrid gradePrincipal) {
		this.gradePrincipal = gradePrincipal;
	}

	public ToolStrip getBarraDeBotoes() {
		return barraDeBotoes;
	}

	public void setBarraDeBotoes(ToolStrip barraDeBotoes) {
		this.barraDeBotoes = barraDeBotoes;
	}
	
	protected abstract DataSource getDataSource();
	
	protected abstract List<ImgButton> getBotoes();
	
	protected abstract List<ListGridField> getCamposDaGrade();
	
	protected abstract void setClickHandlerGrid();
		
}
